<div class="container-fluid">
  <div class="row-fluid">
    <div class="span12">
    <form role="form" id="form" action="{:U('Activity/question_update',array('id'=>$list['id'],'rid'=>$list['rid']))}">    
    <div class="form-group">
      <label for="name">问题</label>
    <input type="text" class="form-control" value="{$list.name}" name="question" required="required" />
   </div>
    <div class="form-group">
      <label for="name">类型</label>
      <select name="type" id="tesetSelect" form="form"  onchange="tt(this.id)">
         <option value="{$list.type}"><if condition="$list.type eq '0'">填写类型</if><if condition="$list.type eq '1'">选择类型</if></option>
        <option value="0">填写类型</option>
         <option value="1">选择类型</option>
      </select>
    </div>
        <div class="form-group" id="checkbox">
            <label for="name">选项</label>
            <button type="button" class="btn btn-primary" id="button">添加选项</button>
        <!--     <button type="button" class="btn btn-danger" id="button_del">减少选项</button> -->
            <volist name="name" id="var">
                <div class="check" style="width:600px" >选项{$i}
                    <input type="text" class="form-control" style="width:600px" name="name[{$key}]" value="{$var}" required="required"  /> 
                    <button type="button" class="btn btn-danger del">删除</button>
                </div>
            </volist>
         </div>
    <button type="submit" class="btn btn-default">提交</button>
</form>
    </div>
  </div>
</div>
 
<script type="text/javascript">
  <?php $b = ((isset($key) && ($key !== ""))?($key+1):2); ?>
  var i='<?php echo $b?>';
  //alert(i);
 //var i ="{$key|default=2}";
// var i="<?php echo ((isset($key) && ($key !== ""))?($key+1):2); ?>";
$("#button").click(function(){
     var html = '<div class="check">选项'+i+'：<input type="text" class="form-control" style="width:600px" name="name['+i+']"><button type="button" class="btn btn-danger del">删除</button></div>';
    $('#checkbox').append(html);
    i++;
 });

$("#checkbox").delegate(".del","click",function(){
  $(this).parents(".check").remove();
});
 /*$("#button_del").click(function(){
    $(".check:last").remove();
    i--;
    if (i<2) {
      alert('全部删除');
    };
 });*/

//根据类型，弹出适当的选项
var a=$('#tesetSelect').val();//选中的值   
//alert(a);
if (a=='0') {
      $("#checkbox").hide();
  };
if (a=='1') {
     $("#checkbox").show();
};
function tt(id) {
  var aa = document.getElementById(id).value;
  var a=aa;
// alert(a);
  if (a=='0') {
      $("#checkbox").hide(); 
  };
  if (a=='1') {
      $("#checkbox").show();
  };
 }
 
</script>